﻿using Common.DataModels;
using Newtonsoft.Json;
using PLC.Domain.Enum;

namespace PLC.Domain.Entity;
/// <summary>
/// 设备配置
/// </summary>
public class DeviceConfig:BaseEntity<DeviceConfig>
{
    /// <summary>
    /// 设备Id
    /// </summary>
    public long DeviceId { get;  set; }
    /// <summary>
    /// 设备名称
    /// </summary>
    public string DeviceName { get;  set; }
    /// <summary>
    /// 设备ip
    /// </summary>
    public string Ip { get;  set; }
    /// <summary>
    /// 设备端口
    /// </summary>
    public int Port { get;  set; }
    /// <summary>
    /// macId
    /// </summary>
    public string MacId { get;  set; }
    /// <summary>
    /// 硬件类型(plc还是上位机)
    /// </summary>
    public int HardwareType { get;  set; }
    /// <summary>
    /// plc品牌
    /// </summary>
    public int? PlcManufacturer { get;  set; }
    /// <summary>
    /// plc通讯协议类型
    /// </summary>
    public int? Protocol { get;  set; }
    /// <summary>
    /// 排序值
    /// </summary>
    public int OrderNum { get;  set; }
    /// <summary>
    /// 状态(启用 停用)
    /// </summary>
    public int Status { get;  set; }
    /// <summary>
    /// 设备类型
    /// </summary>
    public int DeviceType { get;  set; }

    //给efcore使用的构造函数
    public DeviceConfig()
    {

    }
    /// <summary>
    /// 构造函数
    /// </summary>
    /// <param name="deviceId">设备id</param>
    /// <param name="deviceName">设备名称</param>
    /// <param name="ip">ip</param>
    /// <param name="port">端口</param>
    /// <param name="macId">macId</param>
    /// <param name="hanHardwareType">硬件类型(plc或者上位机)</param>
    /// <param name="plcManufacturer">plc品牌</param>
    /// <param name="protocol">plc型号</param>
    /// <param name="creatorId">创建人</param>
    /// <param name="orderNum">排序值</param>
    /// <param name="status">设备状态</param>
    public DeviceConfig(long deviceId,string deviceName,string ip,int port,string macId,int hanHardwareType,int plcManufacturer,int protocol,int creatorId=0,int orderNum=0, int status = (int)EnumStatus.启用)
    {
        this.SetDeviceId(deviceId).SetIp(ip).SetPort(port).SetMacId(macId).SetHanHardwareType(hanHardwareType)
            .SetPlcManufacturer(plcManufacturer).SetProtocol(protocol).SetOrderNum(orderNum).SetStatus(status)
            .SetDeviceName(deviceName).Build(creatorId);
    }

    public override DeviceConfig Build(long creatorId=0)
    {
        base.Init(creatorId);
        return this;
    }

    public DeviceConfig SetProtocol(int protocol)
    {
        this.Protocol = protocol;
        return this;
    }
    public DeviceConfig SetDeviceId(long deviceId)
    {
        this.DeviceId = deviceId;
        return this;
    }

    public DeviceConfig SetIp(string ip)
    {
        this.Ip = ip;
        return this;
    }

    public DeviceConfig SetPort(int port)
    {
        this.Port = port;
        return this;
    }

    public DeviceConfig SetMacId(string macId)
    {
        this.MacId = macId;
        return this;
    }

    public DeviceConfig SetHanHardwareType(int hanHardwareType)
    {
        this.HardwareType = hanHardwareType;
        return this;
    }

    public DeviceConfig SetPlcManufacturer(int plcManufacturer)
    {
        this.PlcManufacturer =plcManufacturer;
        return this;
    }

    public DeviceConfig SetPlcModel(int protocol)
    {
        this.Protocol = protocol;
        return this;
    }

    public DeviceConfig SetOrderNum(int orderNum)
    {
        this.OrderNum = orderNum;
        return this;
    }

    public DeviceConfig SetStatus(int status)
    {
        this.Status = status;
        return this;
    }

    public DeviceConfig SetModifier(long modifierId)
    {
        base.Modifier = modifierId;
        base.ModificationTime = DateTime.Now;
        return this;
    }

    public DeviceConfig SetIsDelete(bool isDelete)
    {
        base.IsDelete = isDelete;
        return this;
    }

    public DeviceConfig SetDeviceName(string deviceName)
    {
        this.DeviceName = deviceName;
        return this;
    }

    public DeviceConfig SetDeviceType(int deviceType)
    {
        this.DeviceType = deviceType;
        return this;
    }

}